﻿package {
	import flash.display.Sprite;
	import flash.geom.Vector3D;
	
	public class InteractiveCube extends Sprite  {
		
		private static const BACKGROUND_WIDTH = 220;
		private static const BACKGROUND_HEIGHT = 220;
	
		private var interactiveArea:Sprite;
		
		private var cube:CubeControl;
		private var links:LinkLoader;
		private var menuItemHandler:MenuItemHandler;
		
		// storing the vertices locally here
		
		//=========================================================================================
		
		public function InteractiveCube() {
			
			interactiveArea = new Sprite();
			this.addChild(interactiveArea);
			
			// centralise so that the cube draws correctly.
			interactiveArea.x = Math.round(BACKGROUND_WIDTH / 2);
			interactiveArea.y = Math.round(BACKGROUND_HEIGHT / 2);
			
			cube = new CubeControl(interactiveArea, BACKGROUND_WIDTH, BACKGROUND_HEIGHT);
			this.addChild(cube); // added this
			
			links = new LinkLoader("Test.xml", this);
			
			menuItemHandler = new MenuItemHandler(interactiveArea);
		}
		
		public function createMenuItems() {
			var numberOfItems = links.getNumberOfItems();
			trace(numberOfItems);
			
			for(var i:int = 0; i < numberOfItems; i++) {
				var itemDescription:String = links.getItemDescriptionAtIndex(i);
				var itemURL:String = links.getItemURLAtIndex(i);
				var menuItemPosition:Vector3D = cube.getVerticeAtIndex(i);
				
				menuItemHandler.addNewItem(menuItemPosition, itemDescription, itemURL);
			}
		}
		
		
		//
		public function verticesChanged(vertices:Vector.<Vector3D>) {
			
		}
	
	}
	
}